// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import 'babel-polyfill'
require('es6-promise').polyfill()
import Vue from 'vue'
import App from './App'

import VeeValidate, { Validator } from 'vee-validate'
import zh_CN from './assets/js/zh_CN'

Validator.extend('mobile', {
  messages: {
    zh_CN: field => '请输入正确的11位手机号码',
  },
  validate: value => {
    return value.length == 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/.test(value)
  },
})

Validator.addLocale(zh_CN)

const config = {
  errorBagName: 'errors',
  delay: 0,
  locale: 'zh_CN',
  messages: null,
  strict: true,
}
Vue.use(VeeValidate, config)

import axios from 'axios'

import {
  Popover,
  Upload,
  Message,
  Dialog,
  Form,
  FormItem,
  Button,
  Input,
  Carousel,
  CarouselItem,
  Radio,
  Pagination,
  Checkbox,
  CheckboxGroup,
  Switch,
  RadioGroup,
  Scrollbar
} from 'element-ui'


Vue.use(Button)
Vue.use(Input)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Dialog)
Vue.use(Popover)
Vue.use(Upload)
Vue.use(Carousel)
Vue.use(CarouselItem)
Vue.use(Radio)
Vue.use(Pagination)
Vue.use(Checkbox)
Vue.use(CheckboxGroup)
Vue.use(Switch)
Vue.use(RadioGroup)
Vue.use(Scrollbar)

import vmodal from 'vue-js-modal'

Vue.use(vmodal)

Vue.prototype.$message = Message
Vue.prototype.setCookie = function(c_name,value,expiredays) {
  var exdate=new Date()
  exdate.setDate(exdate.getDate()+expiredays)
  document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
Vue.prototype.getCookie=function(c_name) {
  if (document.cookie.length>0)
  {
    var  c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1)
    {
      c_start=c_start + c_name.length+1
      var c_end=document.cookie.indexOf(";",c_start)
      if (c_end==-1) c_end=document.cookie.length
      return unescape(document.cookie.substring(c_start,c_end))
    }
  } else {
    return "0"
  }
}


axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
axios.defaults.headers['Video-Id'] = '1'

import qs from 'qs'

// 添加一个请求拦截器
axios.interceptors.request.use(function (config) {
  config.data = qs.stringify(config.data)
  return config
})

// 添加一个返回拦截器
axios.interceptors.response.use(function (response) {
  if (response.config.isFile) { // 临时加上，上传图片返回数据不符合规范
    console.log(response)
    return response.data
  }
  let data = response.data
  console.log(response.config.url, data)
  return data
}, function (error) {
  Message.error('服务器正忙，请稍后重试!')
  return Promise.reject('服务器正忙!')
})

Vue.prototype.$http = axios
// Vue.prototype.$loading = Loading.service
//
// Loading.service({ fullscreen: true, text: '拼命加载中' })

// import chat from './chat'
// Vue.prototype.$io = chat

import './assets/scss/style-index2.scss'
import './assets/less/iview.less'

// mount with global
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  template: '<App/>',
  components: {App},
})





